<template>
  <div class="basicinformation_add">
    <el-main>
      <div>
        <div class="title">
          <span>账号信息</span>

        </div>
        <div style="margin-top: 20px;display: flex;margin-bottom: 20px;">
          <div style="text-align: right;width: 100px;margin-top: 7px;margin-right: 10px;">登录账号</div>
          <div style="width: 300px;">
            <el-select v-model="purchaser.sysId" placeholder="请选择系统用户">
              <el-option
                v-for="item in users"
                :key="item.id"
                :label="item.username"
                :value="item.id"
              />
            </el-select>
          </div>
        </div>
      </div>

      <div style="margin-top: 10px;margin-left:110px;">
        <el-button type="primary" plain @click="funcback" >确定</el-button>
        <el-button style="display: none;" type="primary" plain @click="funcback" >取消</el-button>
      </div>
    </el-main>
  </div>
</template>

<script>
  import { handleActivePath } from '@/utils/routes'
  import { mapActions } from 'vuex'
  import { listsysusers } from "@/api/purchase/supplierapi";
  import { bindsysuser, getPurchaserInfo } from "@/api/purchase/buyerapi";
  export default{
    data() {
      return{
        id: null,
        users: [], //用户列表
        purchaser: {  }, //供应商数据
      }
    },
    async mounted() {
      let data = {
        id:this.$route.params.id
      }
      this.id = data.id;
     let res = await listsysusers()
     this.users = res.data.list;

      let res2 = await getPurchaserInfo(data)
      this.purchaser = res2.data;
      console.log(this.purchaser);
    }
    ,methods:{
      goBack(){
        this.$router.push('/purchase/initialvalue/buyer')
      },
      funcback(){
        this.$confirm('确定绑定该系统用户?', '确定', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
          .then(async () => {
            let data = {id:this.id, sysId: this.purchaser.sysId}
            let res = await bindsysuser(data)
            if(res.status==200){
              this.$message.success('绑定成功')
              this.goBack()
            }
          })
          .catch(() => {})
      }
    }
  }
</script>

<style>
  .basicinformation_add .title {
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
  }

  .basicinformation_add .title span {
    display: inline-block;
    padding-left: 8px;
    font-size: 16px;
    border-left: 4px solid #1890FF;
  }

  .basicinformation_add .title p {
    display: inline;
  }
</style>
